package com.jojo.bubble.controller;

import com.jojo.bubble.entity.Price;
import com.jojo.bubble.service.PriceService;
import com.jojo.bubble.common.domain.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.ObjectUtils;
import com.jojo.bubble.common.enums.JsonResultEnum;

import javax.annotation.Resource;
import java.util.List;

/**
 * 价格表(Price)表控制层
 *
 * @author jojo
 * @since 2023-08-28 05:05:29
 */
@RestController
@RequestMapping("/admin/price")
public class PriceController {
    /**
     * 服务对象
     */
    @Resource
    private PriceService priceService;


    @GetMapping("/list")
    public AjaxResult getList(Price record) {
        List<Price> priceList = priceService.getList(record);
        return AjaxResult.success(priceList);
    }

    @GetMapping("/info")
    public AjaxResult getInfo(Integer id) {
        Price price = priceService.getInfo(id);
        return AjaxResult.success(price);
    }

    @PostMapping("/insert")
    public AjaxResult insert(Price record) {
        priceService.insert(record);
        return AjaxResult.success();
    }

    @PostMapping("/update")
    public AjaxResult update(Price record) {
        Price price = priceService.getInfo(record.getId());
        if (ObjectUtils.isEmpty(price)) {
            return AjaxResult.error(JsonResultEnum.RECORD_NULL);
        }
        priceService.update(record);
        return AjaxResult.success();
    }

    @PostMapping("/delete")
    public AjaxResult delete(int id) {
        priceService.delete(id);
        return AjaxResult.success();
    }
}

